﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using M.Dao.Client.Core;


namespace M.Dao.Client
{   
    /// <summary>
    /// 通用数据检索
    /// </summary>
    public class DBRepository
    {
        /// <summary>
        /// 数据访问对象
        /// </summary>
        public IDataAccess DataAccess { get; set; }

        public string DB { get; set; }

        public string AccessToken { get; set; }
        

        public DBRepository(string daoUrl,string db,string accessToken)
        {
            var dataAccess = new DataAccess(daoUrl);
            this.DB = db;
            this.AccessToken = accessToken;

            this.DataAccess = dataAccess;
        }
        public QueryResult Query(string sql,int pageNo, int pageSize)
        {
            return this.DataAccess.Query(this.DB, this.AccessToken,sql, "0", pageNo, pageSize);
        }
        public QueryResult<T> Query<T>(string sql, int pageNo, int pageSize)
        {
            return this.DataAccess.Query<T>(this.DB, this.AccessToken, sql, "0", pageNo, pageSize);
        }
        
        public QueryResult Query(string sql, string pk, int pageNo, int pageSize)
        {
            return this.DataAccess.Query(this.DB, this.AccessToken, sql, pk, pageNo, pageSize);
        }

        public QueryResult<T> Query<T>(string sql, string pk, int pageNo, int pageSize)
        {
            return this.DataAccess.Query<T>(this.DB, this.AccessToken, sql, pk, pageNo, pageSize);
        }
        public GetResult Get(string sql)
        {
            return this.DataAccess.Get(this.DB, this.AccessToken, sql);
        }

        public WriteResult Write(string sql)
        {
            return this.DataAccess.Write(this.DB, this.AccessToken, sql);
        }

        public ScaleResult Scale(string sql)
        {
            return this.DataAccess.Scale(this.DB, this.AccessToken, sql);
        }

    }
}
